package com.ruoyi.web.core.config;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

/**
 * @Author Mr.Keshihao
 * @Date 2021/2/22 17:16
 * @Version 1.0
 */
@Component
@Slf4j
public class MyMetaObjectHandler implements MetaObjectHandler {

  @Override
  public void insertFill(MetaObject metaObject) {
    log.info("插入时间");
    this.setFieldValByName("createTime", DateUtil.date(), metaObject);
    this.setFieldValByName("updateTime", DateUtil.date(), metaObject);
  }

  @Override
  public void updateFill(MetaObject metaObject) {
    log.info("更新时间");
    this.setFieldValByName("updateTime", DateUtil.date(), metaObject);
  }
}
